<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

<xsl:output method="html"/>

<xsl:template match="/">
<html>
 	<xsl:apply-templates select="*" />
</html>
</xsl:template>

<xsl:template match="DASDSN">
  <head><xsl:call-template name="head"/><title>Directory</title></head>
  <body>
  <table width="100%" border="1">
	<caption><xsl:value-of select="count(DSN)"/> Sources Available</caption>
	<thead>
 	<tr>
 		<th>Id</th>
 		<th>Version</th>
 		<th>URL</th>
 		<th>Description</th>
 	</tr>
 	</thead>
 	<tbody>
		<xsl:for-each select="DSN" >
		<xsl:sort select="SOURCE/@id"/>
		<tr>
			<td>
				<xsl:value-of select="SOURCE/@id" />
			</td>
			<td><xsl:value-of select="SOURCE/@version" /></td>
			<td>
				<xsl:element name="a">
				<xsl:attribute name="href">
					<xsl:value-of select="MAPMASTER" />
				</xsl:attribute>
				<xsl:value-of select="SOURCE/@id" />
				</xsl:element>
			</td>
			
			<td><xsl:value-of select="DESCRIPTION" /></td>
		</tr>
		</xsl:for-each>
 	</tbody>
 </table>


 </body>
</xsl:template>


<xsl:template match="DASEP">
	<head><xsl:call-template name="head"/><title>Entry Points</title></head>
  	<body>
 		<xsl:apply-templates select="ENTRY_POINTS" />
 	</body>
</xsl:template>

<xsl:template match="ENTRY_POINTS">
 <table>
 <caption>Segments available at<br/>
 	<xsl:element name='a'>
 	<xsl:attribute name='href'>
 		<xsl:value-of select="@href"/>
 	</xsl:attribute>
 	<xsl:attribute name='target'>entrydoc</xsl:attribute>
 		<xsl:value-of select="@href"/>
 	</xsl:element>
 	<br/>
 	(version :<xsl:value-of select="@version"/>)
 	</caption>
 	<thead>
 	<tr>
 		<th>id</th>
 		<th>start</th>
 		<th>stop</th>
 		<th>orientation</th>
 		<th>size</th>
 		<th>subpart</th>
 	</tr>
 	</thead>
 	<tbody>
 	<xsl:for-each select="SEGMENT" >
	 <xsl:sort select="@id"/>
	 <tr>
 		<td><xsl:element name="a">
 		<xsl:attribute name="href">
 			<xsl:value-of select="concat('./dassegment.php','?segment=',@id,'&amp;dsn=',../@href)" />
 		</xsl:attribute>
	 		<xsl:value-of select="@id" />
	 	</xsl:element>
	 	</td>
	 	<td><xsl:if test="not(@start)">N/A</xsl:if><xsl:value-of select="@start" /></td>
	 	<td><xsl:if test="not(@stop)">N/A</xsl:if><xsl:value-of select="@stop" /></td>
	 	<td><xsl:if test="not(@orientation)">N/A</xsl:if><xsl:value-of select="@orientation" /></td>
	 	<td><xsl:if test="not(@size)">N/A</xsl:if><xsl:value-of select="@size" /></td>
	 	<td><xsl:if test="not(@subparts)">N/A</xsl:if><xsl:value-of select="@subparts" /></td>
	 </tr>
 	</xsl:for-each>
 	</tbody>
 </table>
</xsl:template>


<xsl:template match="DASTYPES">
	<head><xsl:call-template name="head"/><title>DAS Types</title></head>
  	<body>
 		<xsl:for-each select="GFF">
			<table>
			<caption><xsl:value-of select="count(SEGMENT/TYPE)"/> types available at 
			<xsl:element name='a'>
			<xsl:attribute name='href'>
				<xsl:value-of select="@href"/>
			</xsl:attribute>
			<xsl:attribute name='target'>dastypesdoc</xsl:attribute>
				<xsl:value-of select="@href"/>
			</xsl:element>
			<xsl:text> </xsl:text>(version :<xsl:value-of select="@version"/>)
			<xsl:text> </xsl:text>summary:<xsl:value-of select="@summary"/>
			</caption>
			<thead>
				<tr>
					<th>Segment</th>
					<th>id</th>
					<th>label</th>
					<th>category</th>
					<th>method</th>
					<th>description</th>
				</tr>
			</thead>
			<tbody>
		<xsl:apply-templates select="SEGMENT" />
	</tbody>
	</table>
 		</xsl:for-each>
 	</body>
</xsl:template>



<xsl:template match="SEGMENT">
	<xsl:variable name="seg" select="."/>
		
 	<xsl:for-each select="TYPE" >
 	
	 <xsl:sort select="@id"/>
	 <tr>
	 <xsl:if test="position()=1">
	 	<xsl:element name="th">
			<xsl:attribute name="rowspan"><xsl:value-of select="count($seg/TYPE)"/></xsl:attribute>
			<xsl:value-of select="$seg/@label"/><br/>
			<span style="font-size:75%;color:black;"><xsl:value-of select="$seg/@start"/>-
			<xsl:value-of select="$seg/@stop"/></span>
		</xsl:element>
	 </xsl:if>
		 <td><xsl:value-of select="@id" /></td>
		 <td><xsl:value-of select="@label" /></td>
		 <td><xsl:value-of select="@category" /></td>
		 <td><xsl:value-of select="@method" /></td>
		 <td><xsl:value-of select="." /></td>
	</tr>
 	</xsl:for-each>
 	
</xsl:template>

<xsl:template match="DASDNA">
	<head><xsl:call-template name="head"/><title>DAS DNA</title></head>
  	<body>
 		<xsl:apply-templates select="SEQUENCE" />
 	</body>
</xsl:template>



<xsl:template match="SEQUENCE">
<pre>&gt;<xsl:value-of select="@id"/>:<xsl:value-of select="@start"/>-<xsl:value-of select="@stop"/>|size:<xsl:value-of select="DNA/@length"/>|moltype:<xsl:value-of select="@moltype"/>|version:<xsl:value-of select="@version"/>
<xsl:call-template name="fasta">
	<xsl:with-param name="s" select="translate(DNA,&apos; &apos;,&apos;&apos;)"/>
	<xsl:with-param name="index" select="1"/>
</xsl:call-template></pre>
</xsl:template>


<xsl:template match="DASGFF">
	<head><xsl:call-template name="head"/><title>Features</title></head>
  	<body>
 		<xsl:apply-templates select="GFF" />
 	</body>
</xsl:template>

<xsl:template match="GFF">
	<div style="text-align:center;font-size:200%;width:100%;">
		<xsl:element name="a">
			<xsl:attribute name="href">
			<xsl:value-of select="@href"/>
			</xsl:attribute>
			<xsl:value-of select="@href"/>
		</xsl:element>
	</div>

	<xsl:for-each select="SEGMENT">
	<table>
	<caption>
		<xsl:value-of select="@label"/>
		<xsl:text>:</xsl:text>
		<xsl:value-of select="@start"/>
		<xsl:text>-</xsl:text>
		<xsl:value-of select="@stop"/>
	</caption>
	<thead>
	<tr>
 		<th>label</th>
 		<th>start</th>
 		<th>end</th>
 		<th>+/-</th>
 		<th>phase</th>
 		<th>type</th>
 		<th>category</th>
 		<th>method</th>
 		<th>score</th>
 		<th>group</th>
 		<th>note</th>
 	</tr>
 	</thead>
 	<tbody>
 	<xsl:for-each select="FEATURE" >
	<xsl:sort select="START" data-type="number" />
 	<tr>
	 	<td>
 	 	<xsl:element name='a'>
 	<xsl:attribute name='name'>
 		<xsl:value-of select="@id"/>
 	</xsl:attribute>
 	</xsl:element>
 		<xsl:if test="@label">
	 	<xsl:value-of select="@label" />
	 	</xsl:if>
 		<xsl:if test="not(@label)">
	 	<xsl:value-of select="@id" />
	 	</xsl:if>
	 	
 		<xsl:for-each select="LINK">
	 	[
 	 	<xsl:element name='a'>
		 	<xsl:attribute name='target'>das</xsl:attribute>
		 	<xsl:attribute name='href'>
		 		<xsl:value-of select="@href"/>
		 	</xsl:attribute>
		 	<xsl:attribute name='href'><xsl:value-of select="@href"/></xsl:attribute>
		 	link
 		</xsl:element>
	 	
	 	]</xsl:for-each>
	 	
	 	</td>


	 	<td>
	 	<xsl:value-of select="START" />
	 	</td>
	 	<td>
	 	<xsl:value-of select="END" />
	 	</td>
	 	<td>
	 	<xsl:value-of select="ORIENTATION" />
	 	</td>
	 	<td>
	 	<xsl:value-of select="PHASE" />
	 	</td>

	 	<td>
	 	<xsl:value-of select="TYPE" />
	 	</td>
	 	
	 	<td>
	 	<xsl:value-of select="TYPE/@category" />
	 	</td>
	 	

	 	<td>
	 	<xsl:if test="string-length(METHOD)=0">N/A</xsl:if><xsl:value-of select="METHOD" />
	 	</td>

	 	<td>
	 	<xsl:if test="string-length(SCORE)=0">N/A</xsl:if><xsl:value-of select="SCORE" />
	 	</td>


		<td>
 		<xsl:for-each select="GROUP">
	 	<xsl:if test="LINK">
		<xsl:for-each select="LINK">
	 	[
	 	
 	 	<xsl:element name='a'>
		 	<xsl:attribute name='href'>
		 		<xsl:value-of select="@href"/>
		 	</xsl:attribute>
		 	<xsl:value-of select="../@id"/>
 		</xsl:element>
	 	]</xsl:for-each></xsl:if>
	 	
	 	<xsl:if test="not(LINK)"><xsl:value-of select="@id"/></xsl:if>
	 	<xsl:text> </xsl:text>
		</xsl:for-each>
		</td>

	 	<td>
	 	<xsl:if test="string-length(NOTE)=0">N/A</xsl:if><xsl:value-of select="NOTE" />
	 	</td>

	 </tr>
	
 	</xsl:for-each>
 	</tbody>
	</table>
	
	</xsl:for-each>
	
</xsl:template>





<xsl:template name="fasta">
<xsl:param name="s"/>
<xsl:param name="index"/>
<br/><xsl:value-of select="$index"/><xsl:text>	</xsl:text>
<xsl:choose>
<xsl:when test="string-length($s)&lt;=50">
	<xsl:value-of select="$s"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring($s,1,50)"/>
<xsl:call-template name="fasta">
	<xsl:with-param name="s" select="substring($s,51)"/>
	<xsl:with-param name="index" select="50+$index"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template name="head">
<style>
body {
	background-color:lightgray;
	color:black;
	font-size:18pt;
	margin:30px;
	}
	
table	{
	border-collapse:collapse;
	border-style:solid;
	border-width:1px;
	width:100%;
	}

caption	{
	margin:30px;
	padding:30px;
	font-size:200%;
	}

th	{
	background-color:white;
	color:gray;
	font-size:150%;
	padding:30px;
	}

tr	{
	background-color:white;
	color:black;
	}
tbody	{
	height:500px;
	overflow:auto;
	}
pre	{
	padding:5px;
	font-family:courier;
	font-size:10pt;
	height:500px;
	overflow:auto;
	background-color:white;
	}
</style>
</xsl:template>
</xsl:stylesheet>